__file__ = 'A10.py'
__author__ = 'Jerry Liu'
__date__ = '2016-04-14'

"""
    问题：使用 Python 生成类似于下图中的字母验证码图片
"""
from PIL import Image, ImageFont, ImageDraw
import random

# 图片宽度
width = 100
# 图片高度
height = 40

def getcodeimg():
    choiceCode = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C','D','E']
    # 随机生成10个数字
    code = [random.choice(choiceCode) for i in range(4)]
    print(' '.join(code))
    image = Image.new('RGB', (width, height))
    font = ImageFont.truetype('verdanaz.ttf', 20)
    draw = ImageDraw.Draw(image)
    draw.text((0, 0), ' '.join(code), font=font, fill='red')
    image.save('d://adfaf.png')

if __name__ == '__main__':
    getcodeimg()
